{extend name="layout/detail" /}
{block name="content"}
<script src="__COMMON__/layuiadmin/plugins/codemirror/lib/codemirror.js"></script>
<link rel="stylesheet" href="__COMMON__/layuiadmin/plugins/codemirror/lib/codemirror.css">
<script src="__COMMON__/layuiadmin/plugins/codemirror/mode/javascript/javascript.js"></script>
<div class="td-content-wrap p20">
    <div class="td-content-header">
        <h1>底部自定义区域</h1>
    </div>
    <hr>
    <div class="space-20"></div>
    <form id="form_data" class="layui-form" method="post">
        <input type="hidden" name="data_type" value="bottom">
        <div class="layui-form-item" style="padding-bottom: 0px;">
            <label class="layui-form-label">底部区域代码1：</label>
        </div>
        <div class="layui-form-item" style="border:1px solid #ccc;">
            <div style="position: relative;" data="content" class="">
                <textarea class="" name="bottom_code" id="bottom_code" style="height:200px;">{$system_data.bottom_code|default=''}</textarea>
            </div>
        </div>
        <div class="layui-form-item" style="padding-bottom: 0px;">
            <label class="layui-form-label">底部区域代码2：</label>
        </div>
        <div class="layui-form-item" style="border:1px solid #ccc;">
            <div style="position: relative;" data="content" class="">
                <textarea class="" name="bottom_small_code" id="bottom_small_code" style="height:200px;">{$system_data.bottom_small_code|default=''}</textarea>
            </div>
        </div>
        <hr>
    </form>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <a class="layui-btn" onclick="save();">保存</a>
            <a class="layui-btn" onclick="preview();">预览</a>
            <a class="layui-btn layui-btn-primary" onclick="go_return_url();">取消</a>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
    layui.use(['common', 'ueditor', 'element'], function () {
        let $ = layui.jquery;
        myTextarea = document.getElementById("bottom_code");
        var editor = CodeMirror.fromTextArea(myTextarea, {});

        myTextarea2 = document.getElementById("bottom_small_code");
        var editor2 = CodeMirror.fromTextArea(myTextarea2, {});


        var fn = {
            preview: function () {
                $("#bottom_code").text(editor.getValue());
                $("#bottom_small_code").text(editor2.getValue());

                send_form("form_data", "{:url('preview')}", function (ret) {
                    if (ret.code) {
                        window.open('/?preview=true', 'new');
                    } else {
                        layer.msg(ret.msg);
                        return false;
                    }
                });
            },
            save: function () {
                $("#bottom_code").text(editor.getValue());
                $("#bottom_small_code").text(editor2.getValue());
                send_form("form_data", "{:url('save')}", function (ret) {
                    if (ret.code) {
                        layer.msg(ret.msg, {
                            time: 1200
                        }, function () {
                            location.reload(true);
                        });
                    } else {
                        layer.msg(ret.msg);
                        return false;
                    }
                });
            }
        };
        win_exp(fn);
    });
</script>
{/block}